package com.easyfile.easyfilemaster.config;

import com.easyfile.easyfilemaster.interceptor.NormalInterceptor;
import com.easyfile.easyfilemaster.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * 请求拦截器
 * @author Chenpeman
 */
@Configuration
public class LoginInterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 创建拦截器对象
        HandlerInterceptor normalInterceptor = new NormalInterceptor();
        // 添加拦截器
        registry.addInterceptor(normalInterceptor).addPathPatterns("/**");

        //创建token校验拦截器
        HandlerInterceptor tokenInterceptor = new TokenInterceptor();
        // 白名单
        List<String> patterns = new ArrayList<String>();
        patterns.add("/user/login");
        patterns.add("/user/getVerCode");
        patterns.add("/user/mobileRegister");
        patterns.add("/user/checkToken");
        //添加拦截器
        registry.addInterceptor(tokenInterceptor).addPathPatterns("/**").excludePathPatterns(patterns);
    }
}
